﻿// Copyright (c) Inossem. All rights reserved.
// Licensed under the LGPL-3.0 license. See LICENSE file in the project root for full license information.
using NetMQ;
using NetMQ.Sockets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DWF.Studio.RobotCommunication
{
    internal class MsgSender : IDisposable
    {
        private String _address = "127.0.0.1:8080";

        private RequestSocket _request = null;

        private MsgSender()
        {
        }

        public MsgSender(String strIP, String strPort)
        {
            _address = "tcp://" + strIP + ":" + strPort;
            _request = new RequestSocket(_address);
        }

        /// <summary>
        /// 发送信息
        /// </summary>
        /// <param name="msg"></param>
        public void Send(String strMsg)
        {
            if (String.IsNullOrEmpty(strMsg))
                return;

            if (null == _request)
                return;

            _request.SendFrame(strMsg);

            String strRespMsg;
            _request.TryReceiveFrameString(TimeSpan.FromSeconds(3), out strRespMsg);
        }

        public void Dispose()
        {
            _request.Dispose();
        }
    }
}
